/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package captchabuster;

import com.googlecode.fannj.ActivationFunction;
import com.googlecode.fannj.Fann;
import com.googlecode.fannj.Layer;
import com.googlecode.fannj.Neuron;
import com.googlecode.fannj.Trainer;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author alexnewski
 */
public class FannTrainer {

    private Fann fann;

    public FannTrainer(int inputlayer, int middlelayer, int outputlayer, String inputfile) {

        Layer input = new Layer();
        Neuron e = new Neuron(ActivationFunction.FANN_SIGMOID_SYMMETRIC);
        for (int i = 0; i < inputlayer; i++) {
            input.add(e);
        }
        

        Layer middle = new Layer();
        for (int i = 0; i < middlelayer; i++) {
            middle.add(e);
        }


        Layer output = new Layer();
        for (int i = 0; i < outputlayer; i++) {
            output.add(e);
        }


        List<Layer> network = new ArrayList<Layer>();
        network.add(input);
        network.add(middle);
        network.add(output);

        Fann fann = new Fann(network);

        Trainer train = new Trainer(fann);
        Float error = 0.1f;
        train.train(inputfile, 500, 1000, error);

        this.fann = fann;
    }

    public Fann getFann() {
        return fann;
    }

    public void setFann(Fann fann) {
        this.fann = fann;
    }
}
